<template>
	<view>
		<u-toast ref="uToast"></u-toast>
		<u-tabbar :value="tabBarValue" @change="tabBarChange" :fixed="true" :placeholder="true" :safeAreaInsetBottom="true"
			activeColor="#d81e06" :border="false">
			<u-tabbar-item @click="tabBarClick(item)" v-for="(item) in tabBarList" :key="item['pagePath']"
				:text="item['text']" :icon="item['iconClass']" :dot="item.isDot">
			</u-tabbar-item>
		</u-tabbar>
	</view>
</template>

<script>
	import {
		mapGetters
	} from 'vuex'
	export default {
		data() {
			return {
				tabBarList: [{
						text: '发现',
						iconClass: 'eye',
						pagePath: '/pages/discover/index'
					},
					{
						text: '招亲',
						iconClass: 'man-add',
						pagePath: '/pages/match/index'
					},
					{
						text: '消息',
						iconClass: 'chat',
						pagePath: '/pages/message/index',
						isDot: true
					},
					{
						text: '通讯录',
						iconClass: 'file-text',
						pagePath: '/pages/contacts/index'
					},
					{
						text: '我',
						iconClass: 'account-fill',
						pagePath: '/pages/my/index'
					}
				]
			}
		},
		computed: {
			...mapGetters('common', ["vuexGetTabbarInfo"]),
			tabBarValue() {
				return this.vuexGetTabbarInfo.index
			}
		},
		onLoad() {
			this.$store.commit("common/SET_TABBAR_OBJ", {
				index: 0
			});
		},
		methods: {
			// tabBar切换
			tabBarClick(item, index) {
				uni.redirectTo({
					url: item.pagePath
				});
			},
			tabBarChange(index) {
				this.$refs.uToast.show({
					type: 'loading',
					message: '加载中..'
				});
				this.$store.commit("common/SET_TABBAR_OBJ", {
					index
				});
			}
		}
	}
</script>

<style>
	.tabBar {
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		display: flex;
		justify-content: space-around;
		align-items: center;
		height: 50px;
		background-color: #ffffff;
		box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
	}

	.tabbar-item {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.iconfont {
		font-size: 24px;
		color: #999;
	}

	.tabbar-text {
		font-size: 12px;
		color: #999;
		margin-top: 4px;
	}

	.active .iconfont,
	.active .tabbar-text {
		color: #007AFF;
	}
</style>